package com.car.test;

import java.io.IOException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import org.json.JSONException;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;




public class JsonTest2 {
	public String getString() {
		String res = null;
		Document doc = null;
		try {
			doc = Jsoup
					.connect(
							"http://api.car.bitauto.com/CarInfo/MasterBrandToSerialNew.aspx?type=1&pid=0&rt=master&serias=m&key=master_0_1_m")
					.ignoreContentType(true).get();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return doc.text().split("=")[1];
	}

	
	 public static Map toMap(String jsonString) throws JSONException {

	        JSONObject jsonObject = new JSONObject(jsonString);
	        
	        Map result = new HashMap();
	        Iterator iterator = jsonObject.keys();
	        String key = null;
	        String value = null;
	        
	        while (iterator.hasNext()) {

	            key = (String) iterator.next();
	            value = jsonObject.getString(key);
	            result.put(key, value);

	        }
	        return result;

	    }

	 
	public static void main(String[] args) throws JSONException {
		JsonTest2 jt = new JsonTest2();
		
		String data1="{\"m9\":[{\"id\":\"9\",\"name\":\"奥迪\",\"pid\":\"0\"}],\"m97\":[{\"id\":\"97\",\"name\":\"阿斯顿·马丁\",\"pid\":\"0\"}]}";
		//System.out.println(data1);
		String data2="{\"map\":[{\"id\":\"9\",\"name\":\"奥迪\",\"pid\":\"0\"}],\"employee\":[{\"id\":\"female\",\"name\":\"Alexia\",\"age\":\"23\"}]}";
		Map map=JsonTest2.toMap(data1);
		System.out.println();
		
		
		
	}

}
